ISOTHERMAL_GAS
Overview
Calculate mass flow rate for isothermal compressible gas flow in a pipe.
Excel Usage
=ISOTHERMAL_GAS(rho, fd, p_inlet, p_outlet, length, diameter)
rho(float, required): Average density of gas in pipe [kg/m³]fd(float, required): Darcy friction factor [-]p_inlet(float, required): Inlet pressure [Pa]p_outlet(float, required): Outlet pressure [Pa]length(float, required): Length of pipe [m]diameter(float, required): Diameter of pipe [m]
Returns (float): Mass flow rate of gas through pipe [kg/s]
Examples
Example 1: Standard gas pipeline flow
Inputs:
| rho | fd | p_inlet | p_outlet | length | diameter |
|---|---|---|---|---|---|
| 11.3 | 0.00185 | 1000000 | 900000 | 1000 | 0.5 |
Excel formula:
=ISOTHERMAL_GAS(11.3, 0.00185, 1000000, 900000, 1000, 0.5)
Expected output:
145.4847572636031
Example 2: High pressure drop case
Inputs:
| rho | fd | p_inlet | p_outlet | length | diameter |
|---|---|---|---|---|---|
| 10 | 0.02 | 2000000 | 1000000 | 5000 | 0.3 |
Excel formula:
=ISOTHERMAL_GAS(10, 0.02, 2000000, 1000000, 5000, 0.3)
Expected output:
14.963646173696276
Example 3: Long pipeline with low friction
Inputs:
| rho | fd | p_inlet | p_outlet | length | diameter |
|---|---|---|---|---|---|
| 8.5 | 0.015 | 5000000 | 4000000 | 50000 | 0.6 |
Excel formula:
=ISOTHERMAL_GAS(8.5, 0.015, 5000000, 4000000, 50000, 0.6)
Expected output:
31.275594727821595
Example 4: Small diameter pipe
Inputs:
| rho | fd | p_inlet | p_outlet | length | diameter |
|---|---|---|---|---|---|
| 15 | 0.025 | 800000 | 700000 | 100 | 0.1 |
Excel formula:
=ISOTHERMAL_GAS(15, 0.025, 800000, 700000, 100, 0.1)
Expected output:
2.620346761681036
Python Code
import micropip
await micropip.install(["fluids"])
from fluids.compressible import isothermal_gas as fluids_iso_gas
def isothermal_gas(rho, fd, p_inlet, p_outlet, length, diameter):
"""
Calculate mass flow rate for isothermal compressible gas flow in a pipe.
See: https://fluids.readthedocs.io/fluids.compressible.html#fluids.compressible.isothermal_gas
This example function is provided as-is without any representation of accuracy.
Args:
rho (float): Average density of gas in pipe [kg/m³]
fd (float): Darcy friction factor [-]
p_inlet (float): Inlet pressure [Pa]
p_outlet (float): Outlet pressure [Pa]
length (float): Length of pipe [m]
diameter (float): Diameter of pipe [m]
Returns:
float: Mass flow rate of gas through pipe [kg/s]
"""
# Validate and convert inputs
try:
rho = float(rho)
except (ValueError, TypeError):
return "Invalid input: rho must be a number."
try:
fd = float(fd)
except (ValueError, TypeError):
return "Invalid input: fd must be a number."
try:
p_inlet = float(p_inlet)
except (ValueError, TypeError):
return "Invalid input: p_inlet must be a number."
try:
p_outlet = float(p_outlet)
except (ValueError, TypeError):
return "Invalid input: p_outlet must be a number."
try:
length = float(length)
except (ValueError, TypeError):
return "Invalid input: length must be a number."
try:
diameter = float(diameter)
except (ValueError, TypeError):
return "Invalid input: diameter must be a number."
# Validation
if rho <= 0:
return "Invalid input: rho must be positive."
if fd <= 0:
return "Invalid input: fd must be positive."
if p_inlet <= 0:
return "Invalid input: p_inlet must be positive."
if p_outlet < 0:
return "Invalid input: p_outlet must be non-negative."
if p_outlet >= p_inlet:
return "Invalid input: p_outlet must be less than p_inlet."
if length <= 0:
return "Invalid input: length must be positive."
if diameter <= 0:
return "Invalid input: diameter must be positive."
try:
result = fluids_iso_gas(rho=rho, fd=fd, P1=p_inlet, P2=p_outlet, L=length, D=diameter)
return float(result)
except Exception as e:
return f"Error: Failed to compute isothermal gas flow: {str(e)}"